import {
		getAction,
		postAction,
		editAction,
		removeAction,
		detailAction,
	} from "@/api/api";
import taskApi from '@/api/task';
import deptApi from '@/api/dept';
import taskdeptApi from '@/api/taskdept';
import roundApi from '@/api/round';
import matterApi from '@/api/matter';
import fankuiApi from '@/api/fankui';
export const mixin = {
	props: {},
	computed: {},
	watch: {},
	data() {
		return {
			// 遮罩层
			loading: true,
			//弹层内的名称
			pageName: '',
			// 选中数组
			ids: [],
			// 非单个禁用
			single: true,
			// 非多个禁用
			multiple: true,
			// 总条数
			total: 0,
			// 任务模板表格数据
			list: [],
			// 表单参数
			form: {},
		}
	},
	created() {
		if (this.autoGetList) {
			this.getList();
		}
	},
	methods: {
		goPath(e){
			this.$router.push(e)
		},
		getList(name,fun = null) {
			this.loading = true;
			roundApi.getModelPagination(this.queryParams,null,null).then(res => {
				console.log(res)
				if(fun){
					res.rows = fun(res.rows)
				}
				console.log(res.rows)
				this.list = res.data.list;
				this.total = res.data.total;
				this.loading = false;
			})
		},
		/** 搜索按钮操作 */
		handleQuery() {
			this.queryParams.pageNum = 1;
			this.getList();
		},
		/** 重置按钮操作 */
		resetQuery() {
			// this.resetForm("queryForm");
			let obj = {...this.queryParams}
			for(let i in obj){
				obj[i] = null
			}
			this.queryParams = obj;
			this.handleQuery();
		},
		/** 新增按钮操作 */
		handleAdd(type = true) {
			if(type){
				this.reset();
			}
			this.$refs.mylog.open = true;
			this.$refs.mylog.title = this.pageName;
		},
		/** 修改按钮操作 */
		handleUpdate(row,name) {
			this.reset();
			const id = row.id || this.ids
			detailAction(`${this.apiUrl}`,id).then(res => {
				this.form = res.data;
				this.$refs.mylog.open = true;
				this.$refs.mylog.title = this.pageName;
			});
		},
		//修改下拉列表
		handleCommand(e,item,name) {
			if (e == 'edit') {
				this.handleUpdate(item)
			}
			if (e == 'remove') {
				this.handleDelete(item)
			}
		},
		/** 导出按钮操作 */
		handleExport(name) {
			this.download(`${this.apiUrl}/export`, {
				...this.queryParams
			}, `${name}_${new Date().getTime()}.xlsx`)
		},
		/** 删除按钮操作 */
		handleDelete(row,url = null) {
			console.log(row)
			const ids = row.id || this.ids;
			this.$modal.confirm('是否确认删除任务模板编号为"' + ids + '"的数据项？').then(()=> {
				return removeAction(`${url??this.apiUrl}`,ids)
			}).then(() => {
				this.getList();
				this.$modal.msgSuccess("删除成功");
			}).catch(() => {});
		},
		/** 提交按钮 */
		submitForm(url = null) {
			this.$refs["form"].validate(valid => {
				if (valid) {
					if (this.form.id != null) {
						editAction(`${url??this.apiUrl}`,this.form).then(response => {
							this.$modal.msgSuccess("修改成功");
							this.$refs.mylog.open = false;
							this.getList();
						});
					} else {
						//this.form.id = new Date().getTime()
						
						postAction(`${url??this.apiUrl}`,this.form).then(response => {
							this.$modal.msgSuccess("新增成功");
							this.$refs.mylog.open = false;
							this.getList();
		
						});
					}
				}
			});
		},
		// 取消按钮
		cancel() {
			this.open = false;
			this.reset();
		},
	},
}